<?php

namespace Lib;

class Trans {

    private static $words;
    private static $instance;
    
    
    
    public static function getInstance($ini_file = 'Config/trans.ini', $locale = 'ru'){
        if(!self::$instance)
            self::$instance = new Trans($ini_file, $locale);
        return self::$instance;
    }


    private function __construct($ini_file, $locale) {
        if(!isset($_SESSION['locale'])){
            $_SESSION['locale'] = $locale;
        }
        if(!self::$words){
            self::$words = parse_ini_file(SITE_PATH . $ini_file, TRUE);
        }
    }
    
    public function get($word) {
        return isset(self::$words[$word][$_SESSION['locale']]) ? self::$words[$word][$_SESSION['locale']] : $word;
    }
    
    public function setLocale($locale) {
        $_SESSION['locale'] = $locale;
    }
    
    public function getLocale() {
        return $_SESSION['locale'];
    }

}

?>
